home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / p_msys / msysb116.exe / SCAN757.ASM < prev    next >
Assembly Source File  |  1993-11-26  |  8KB  |  257 lines

  1. ; scan757.asm
  2.  
  3. ;       Here is sample source for a Scan TSR to be used with the MSYS
  4. ;       Pactor scan command
  5.  
  6. ;       This example is for the Yeasu FT-757GXII. It may work for other
  7. ;       Yeaus HF radios without modification. The FT-757 requires 
  8. ;       the following command format:   
  9. ;           pp pp pp pp cc
  10. ;               where pp are 4 parameter bytes and cc is the operation
  11. ;               to perform.
  12. ;
  13. ;       For command 0A hex, the frequency is given in 4 bytes, using
  14. ;       BCD (binary coded decimal) with the least significant byte
  15. ;       first. The frequency is expressed in tens of Hz. Thus, for a frequency
  16. ;       of 14,123.450 KHz, the four bytes would be
  17. ;               45 23 41 01 
  18. ;
  19. ;       The complete set of 5 bytes used to set a frequency of 7.021 MHz
  20. ;       would be (in hex):
  21. ;               00 21 70 00 0A
  22. ;       to produce the executable for this program, use the following
  23. ;
  24. ;       asm     scan757.asm     {tasm or masm may be used}
  25. ;       link    scan757;        {tlink may be used}
  26. ;       exe2bin scan757         {makes .com file out of .exe file}
  27.  
  28.  
  29. code    segment
  30.         assume  cs:code,ds:code
  31.  
  32. main    proc    far
  33.         org     0
  34. segorg  equ     $
  35.         org     100h
  36. start:  jmp     install
  37.  
  38.  
  39. port    dw      0               ;control uart base address
  40. ten     dw      10              ;divisor
  41. thousand dw     1000
  42.  
  43. freq    db      'freq'          ;frequency in BCD, LSB first
  44.         db      0Ah
  45.  
  46. temp    db      'hhhkkkmm0'      ;work space build freq
  47. savequot dw     0
  48.  
  49. ;debug   db      'xx $'
  50.  
  51. putser  proc near
  52. ;       send char in AL
  53.         push    dx
  54.         push    ax
  55.         mov     dx,port
  56.         add     dx,5            ;line status register
  57. wait1:  in      al,dx
  58.         and     al,20h          ;check transmit holding reg 
  59.         jz      wait1           ;not ready yet
  60.         pop     ax
  61.         mov     dx,port
  62.         out     dx,al           ;send char to serial port
  63.  
  64.  
  65. ;       The following commented out lines were used for debugging. They
  66. ;       displayed each byte sent to the radio in hex. 
  67. ;        push    ax
  68. ;        push    bx
  69. ;        push    cx
  70. ;        push    dx
  71. ;        mov     ah,al
  72. ;        mov     cl,4
  73. ;        shr     al,cl
  74. ;        add     al,'0'
  75. ;        cmp     al,'9'
  76. ;        jle     q1
  77. ;        add     al,7
  78. ;q1:
  79. ;        mov     debug,al
  80. ;        and     ah,15
  81. ;        add     ah,'0'
  82. ;        cmp     ah,'9'
  83. ;        jle     q2
  84. ;        add     ah,7
  85. ;q2:
  86. ;        mov     debug+1,ah
  87. ;        mov     dx,offset debug
  88. ;        mov     ah,9
  89. ;        int     21h
  90. ;        pop     dx
  91. ;        pop     cx
  92. ;        pop     bx
  93. ;        pop     ax 
  94.  
  95.         pop     dx
  96.         ret
  97. putser  endp
  98.  
  99. putserstr proc near
  100. ;       sends string pointed to by bx, cx has number of bytes
  101.         push    ax
  102.         push    bx
  103.         push    cx
  104. psloop:
  105.         mov     al, byte ptr [bx]
  106.         call    putser
  107.         inc     bx
  108.         dec     cx
  109.         cmp     cx,0
  110.         je      putserstrexit
  111.         jmp     psloop
  112. putserstrexit:
  113.         pop     cx
  114.         pop     bx
  115.         pop     ax
  116.         ret
  117. putserstr endp
  118.  
  119.  
  120.  
  121. handler:
  122.         STI                     ; enable interrupts
  123. ;                               ; If we don't we will get overruns
  124. ;                               ; on the serial ports for the tnc's
  125.         push    ds              ; save some registers
  126.         push    ax
  127.         push    ax              ; save ax a second time
  128.         mov     ax,cs
  129.         mov     ds,ax           ; set up ds
  130.         pop     ax              ; get back the ax we were called with
  131.  
  132. ;
  133. ;       upon entry, dx has port address
  134. ;                   ax has high order part of frequency
  135. ;                   bx has low order part of frequency
  136.         mov     port,dx
  137.  
  138. ;       The Yaesu manual says it wants 2 stop bits. Normally MSYS
  139. ;       sets up the port for 1 stop bit. The next 5 instructions
  140. ;       force the uart to 2 stop bits, 8 data bits
  141.         push    ax              ;save ax
  142.         add     dx,3
  143.         mov     al,7            ;2 stop, 8 data, no parity
  144.         out     dx,al
  145.         pop     ax              ;restore ax
  146.  
  147. ; div divides DX:AX giving quot in AX, rem in DX
  148.         mov     dx,ax
  149.         mov     ax,bx   
  150. ;       We have a bit of a problem in that the DIV instruction 
  151. ;       requires that the quotient will fit in a 16 bit register.
  152. ;       But a frequency like 14.350, which is 14350000 in the 
  153. ;       long (32 bit) variable and when divided by 10 the 
  154. ;       quotient won't fit in 16 bits (AX). 
  155. ;
  156. ;       So here is what we will do...
  157. ;       First divide the original frequency by 1000. This will
  158. ;       give a quotient <= 30000 which will fit.
  159. ;       The remainder from this division will be run thru the
  160. ;       divide by 10 to get the digits loop three times.
  161. ;       Then we take the quotient and use the same instructions
  162. ;       to do the other 5 required digits
  163.  
  164.         div     thousand        ;rem in dx, quot in ax
  165.         mov     savequot,ax
  166.         mov     ax,dx           ;set up for divide
  167.         sub     dx,dx
  168.         
  169.         mov     cx,3                    ;number of digits
  170.         mov     bx,offset temp          ;place for first
  171.  
  172. dloop1:
  173.         div     ten
  174.         add     dl,'0'                  ;convert to ascii
  175.         mov     byte ptr [bx],dl
  176.         sub     dx,dx
  177.         inc     bx
  178.         dec     cx
  179.         cmp     cx,0
  180.         jne     dloop1
  181.         
  182.         mov     ax,savequot
  183.         sub     dx,dx
  184.         mov     cx,5
  185. dloop2:
  186.         div     ten
  187.         add     dl,'0'                  ;convert to ascii
  188.         mov     byte ptr [bx],dl
  189.         sub     dx,dx
  190.         inc     bx
  191.         dec     cx
  192.         cmp     cx,0
  193.         jne     dloop2
  194.  
  195. ;       We now have 8 ascii bytes at temp, lsb first that is the freq
  196. ;       We need to pack them into bcd, putting them at label freq
  197.         mov     ah,temp+2
  198.         and     ah,0Fh                  ;convert to bcd
  199.         mov     cl,4
  200.         shl     ah,cl                    ;shift left 4
  201.         mov     al,temp+1
  202.         and     al,0Fh
  203.         add     ah,al
  204.         mov     freq,ah
  205.  
  206.         mov     ah,temp+4
  207.         and     ah,0Fh                  ;convert to bcd
  208.         shl     ah,cl                    ;shift left 4
  209.         mov     al,temp+3
  210.         and     al,0Fh
  211.         add     ah,al
  212.         mov     freq+1,ah
  213.  
  214.         mov     ah,temp+6
  215.         and     ah,0Fh                  ;convert to bcd
  216.         shl     ah,cl                    ;shift left 4
  217.         mov     al,temp+5
  218.         and     al,0Fh
  219.         add     ah,al
  220.         mov     freq+2,ah
  221.  
  222.         mov     ah,temp+8
  223.         and     ah,0Fh                  ;convert to bcd
  224.         shl     ah,cl                    ;shift left 4
  225.         mov     al,temp+7
  226.         and     al,0Fh
  227.         add     ah,al
  228.         mov     freq+3,ah
  229.  
  230.         mov     cx,5
  231.         mov     bx,offset freq
  232.         call    putserstr
  233.  
  234.         pop     ax
  235.         pop     ds
  236.         iret
  237. main    endp
  238.  
  239.  
  240. install:
  241.         mov     dx,offset msg1
  242.         mov     ah,9
  243.         int     21h
  244.         mov     dx,offset handler
  245.         mov     al,0D4h
  246.         mov     ah,25h
  247.         int     21h
  248.  
  249.         mov     dx,(offset install - segorg +15) shr 4
  250.         mov     ah,31h
  251.         int     21h
  252.  
  253. msg1    db      'Scan TSR loaded for Yeasu FT-757GXII using Int D4',13,10,'$'
  254.  
  255. code    ends
  256.         end     start
  257.